package com.cloud.form.api.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cloud.form.api.entity.FormDataPush;
import com.cloud.form.api.mapper.FormDataPushMapper;
import com.cloud.form.api.service.FormDataPushService;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
@Transactional
public class FormDataPushServiceImpl implements FormDataPushService {

	@Autowired
	private FormDataPushMapper formDataPushMapper;

	@Override
	public List<FormDataPush> listDataPush(long formId) {
		Example example = new Example(FormDataPush.class);
		Criteria criteria = example.createCriteria();
		criteria.andEqualTo("formId", formId);
		example.orderBy("dataPushId").asc();
		return formDataPushMapper.selectByExample(example);
	}

	@Override
	public FormDataPush showDetail(long id) {
		return formDataPushMapper.selectByPrimaryKey(id);
	}

	@Override
	public long delete(long id) {
		formDataPushMapper.deleteByPrimaryKey(id);
		return id;
	}

	@Override
	public FormDataPush createUpdate(FormDataPush dataPush) {
		Long dataPushId = dataPush.getDataPushId();
		if (null != dataPushId && dataPushId >= 0) {
			formDataPushMapper.updateByPrimaryKey(dataPush);
		} else {
			formDataPushMapper.insert(dataPush);
		}
		return dataPush;
	}

}
